INLCUDES = -I./Shared
CFLAGSO = -ansi -pedantic-errors -Wall -g $(INLCUDES)
CFLAGSC = -ansi -pedantic-errors -Wall -c -g $(INLCUDES)
HASH_LOCATION = ./$(SHARED)/md5.o ./$(SHARED)/sha1.o
SHARED = Shared
vpath %.h Shared
vpath %.c Part1 Part2 Part3 Shared Test
vpath %.o Part1 Part2 Part3 Shared Test
TEST_NAME = test_part3

########################
##### Build Parts ######
########################

all: create_authentication authenticate exhaustive_table_generator exhaustive_query create_rainbow_table crack_using_rainbow_table

create_authentication: create_authentication

authenticate: authenticate

exhaustive_table_generator: exhaustive_table_generator

exhaustive_query: exhaustive_query

create_rainbow_table: create_rainbow_table

crack_using_rainbow_table: crack_using_rainbow_table

######################	
###### Clean #########
######################

clean: 
	-rm Shared/*.o
	-rm Part1/*.o
	-rm Part2/*.o
	-rm Part3/*.o
	-rm create_authentication
	-rm authenticate
	-rm exhaustive_table_generator
	-rm exhaustive_query
	-rm create_rainbow_table
	-rm crack_using_rainbow_table

#######################
##### Executables #####
#######################

# Part 1 - contains two executables: create_authentication and authenticate

create_authentication: create_authentication.o part1_shared.o misc.o hash
	gcc $(CFLAGSO) ./Part1/create_authentication.o ./$(SHARED)/part1_shared.o ./$(SHARED)/misc.o $(HASH_LOCATION) -o create_authentication

create_authentication.o: create_authentication.c
	gcc $(CFLAGSC) ./Part1/create_authentication.c -o ./Part1/create_authentication.o
	
authenticate: authenticate.o part1_shared.o misc.o hash
	gcc $(CFLAGSO) ./Part1/authenticate.o ./$(SHARED)/part1_shared.o ./$(SHARED)/misc.o $(HASH_LOCATION) -o authenticate

authenticate.o: authenticate.c
	gcc $(CFLAGSC) ./Part1/authenticate.c -o ./Part1/authenticate.o

part1_shared.o: part1_shared.c part1_shared.h
	gcc $(CFLAGSC) ./$(SHARED)/part1_shared.c -o ./$(SHARED)/part1_shared.o

# Part 2 - contains two executables: exhaustive_table_generator and exhaustive_query

exhaustive_table_generator:  exhaustive_table_generator.o part2-3_shared.o misc.o DEHT.o hash
	gcc $(CFLAGSO) ./Part2/exhaustive_table_generator.o ./$(SHARED)/part2-3_shared.o ./$(SHARED)/misc.o ./$(SHARED)/DEHT.o $(HASH_LOCATION) -o exhaustive_table_generator

exhaustive_table_generator.o: exhaustive_table_generator.c
	gcc $(CFLAGSC) ./Part2/exhaustive_table_generator.c -o ./Part2/exhaustive_table_generator.o

exhaustive_query: exhaustive_query.o part2-3_shared.o misc.o DEHT.o hash
	gcc $(CFLAGSO) ./Part2/exhaustive_query.o ./$(SHARED)/part2-3_shared.o ./$(SHARED)/misc.o ./$(SHARED)/DEHT.o $(HASH_LOCATION) -o exhaustive_query

exhaustive_query.o: exhaustive_query.c
	gcc $(CFLAGSC) ./Part2/exhaustive_query.c -o ./Part2/exhaustive_query.o

part2-3_shared.o: part2-3_shared.c part2-3_shared.h
	gcc $(CFLAGSC) ./$(SHARED)/part2-3_shared.c -o ./$(SHARED)/part2-3_shared.o

# Part 2 - contains two executables: create_rainbow_table and crack_using_rainbow_table

create_rainbow_table: create_rainbow_table.o part2-3_shared.o part3_shared.o misc.o DEHT.o hash
	gcc $(CFLAGS0) ./Part3/create_rainbow_table.o ./$(SHARED)/part2-3_shared.o ./$(SHARED)/part3_shared.o ./$(SHARED)/misc.o ./$(SHARED)/DEHT.o $(HASH_LOCATION) -o create_rainbow_table

create_rainbow_table.o: create_rainbow_table.c
	gcc $(CFLAGSC) ./Part3/create_rainbow_table.c -o ./Part3/create_rainbow_table.o

crack_using_rainbow_table: crack_using_rainbow_table.o part2-3_shared.o part3_shared.o misc.o DEHT.o hash
	gcc $(CFLAGS0) ./Part3/crack_using_rainbow_table.o ./$(SHARED)/part2-3_shared.o ./$(SHARED)/part3_shared.o ./$(SHARED)/misc.o ./$(SHARED)/DEHT.o $(HASH_LOCATION) -o crack_using_rainbow_table

crack_using_rainbow_table.o: crack_using_rainbow_table.c
	gcc $(CFLAGSC) ./Part3/crack_using_rainbow_table.c -o ./Part3/crack_using_rainbow_table.o

part3_shared.o: part3_shared.c part3_shared.h
	gcc $(CFLAGSC) ./$(SHARED)/part3_shared.c -o ./$(SHARED)/part3_shared.o 


# shared files used by all parts of the project

hash: md5.o sha1.o

md5.o: md5.c md5.h
	gcc $(CFLAGSC) ./$(SHARED)/md5.c -o ./$(SHARED)/md5.o
	
sha1.o: sha1.c sha1.h
	gcc $(CFLAGSC) ./$(SHARED)/sha1.c -o ./$(SHARED)/sha1.o

misc.o: misc.c misc.h
	gcc $(CFLAGSC) ./$(SHARED)/misc.c -o ./$(SHARED)/misc.o

DEHT.o: DEHT.c DEHT.h
	gcc $(CFLAGSC) ./$(SHARED)/DEHT.c -o ./$(SHARED)/DEHT.o

#######################
######   Test #########
#######################

test: $(TEST_NAME)

$(TEST_NAME): $(TEST_NAME).o part2-3_shared.o part3_shared.o misc.o DEHT.o hash
	gcc $(CFLAGSO) ./Test/$(TEST_NAME).o ./$(SHARED)/part2-3_shared.o ./$(SHARED)/part3_shared.o ./$(SHARED)/misc.o ./$(SHARED)/DEHT.o $(HASH_LOCATION) -o $(TEST_NAME)

$(TEST_NAME).o: $(TEST_NAME).c
	gcc $(CFLAGSC) ./Test/$(TEST_NAME).c -o ./Test/$(TEST_NAME).o

